//
//  UserInfoViewController.swift
//  麦子洗衣 会员中心页面
//
//  Created by yangyifan on 15/10/22.
//  Copyright © 2015年 womenshuo. All rights reserved.
//

import UIKit
import SwiftyUserDefaults

class UserInfoViewController: UIViewController {

    @IBOutlet var phone: UILabel!
    
    private var phoneData: String?   = Defaults[.phone]!
    private var isLoginData: Bool? = Defaults[.isLogin]!
    
    let bounds = UIScreen.mainScreen().bounds
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //初始化
        self.initialize()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //设置 视图
    private func setView() {
        phone.text = self.phoneData
    }
    
    //初始化
    private func initialize() {
        //设置视图
        self.setView()
        
        if self.isLoginData == false || self.phoneData == "" {
            //设置背景
            let view = UIView(frame: bounds)
            view.backgroundColor = UIColor.whiteColor()
            
            let btnWidth: CGFloat   = 100.0//按钮宽度
            let btnHeight: CGFloat  = 30.0//按钮高度
            
            //设置按钮
            let goToLoginBtn = UIButton(frame: CGRect(x: (bounds.width - btnWidth ) / 2, y: (bounds.height - btnHeight) / 2, width: btnWidth, height: btnHeight))
            goToLoginBtn.setTitle("去登录", forState: UIControlState.Normal)
            goToLoginBtn.backgroundColor = UIColor(red: 40 / 255.0, green: 204.0 / 255.0 , blue: 252.0 / 255.0, alpha: 1)
            goToLoginBtn.addTarget(self, action: "goToLogin", forControlEvents: UIControlEvents.TouchUpInside)
            view.addSubview(goToLoginBtn)
            
            self.view.addSubview(view)
        }
    }
    
    //跳转到登录页面
    func goToLogin() {
        self.navigationController?.pushViewController(Redirect.redirectToLogin(), animated: true)
    }

}
